package de.bazinga.rotw.network.message;

import com.captiveimagination.jgn.message.Message;
import com.captiveimagination.jgn.message.type.CertifiedMessage;
import com.captiveimagination.jgn.message.type.PlayerMessage;
import com.captiveimagination.jgn.message.type.TimestampedMessage;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.network.Server;
import de.bazinga.rotw.person.OpponentList;

public class TeamChangeMessage extends Message implements CertifiedMessage, PlayerMessage, TimestampedMessage, GameMessage {
	private int team = 1;

	public void setTeam(int team) {
		this.team = team;
	}

	public int getTeam() {
		return team;
	}


	public void handleMessage(RotwGameState game, Message msg, boolean server) {
		if(!(msg instanceof TeamChangeMessage)) return ;

		// Player touched a item
		TeamChangeMessage message = (TeamChangeMessage)msg;
		
		if(server) {
			// Player switched Teams
			OpponentList.getInstance().getOpponent(message.getPlayerId())
				.setTeam(message.getTeam());
			
			// Send new Statistics
			((Server)game.getSyncManager()).updateScore();
		}
	}
}